import { defineRule } from 'vee-validate';

// 必填验证
defineRule('required', (value: string) => {
  if (!value || value.length === 0) {
    return 'This field is required';
  }
  return true;
});

// 邮箱验证
defineRule('email', (value: string) => {
  // Field is empty, should pass
  if (!value || value.length === 0) {
    return true;
  }
  // Check if email
  if (!/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/.test(value)) {
    return 'This field must be a valid email';
  }
  return true;
});
